import { drawCircle, PositionArray } from "../canvas/utils/Circle";
import { drawRect } from "../canvas/utils/Rect";

import { PenLike, StyleArray } from "./PenLike";

export class Pen extends PenLike {
    name = "钢笔";
    constructor() {
        super();
    }
    GetDistanceArray() {
        const r = this.size - 1;
        return r === 0 ? ([[0, 0, 0]] as PositionArray[]) : drawCircle(r, r);
    }
    StyleConvert(
        positionArray: PositionArray[],
        color: number,
        alpha: number
    ): StyleArray[] {
        return positionArray.map(([x, y, distance]) => {
            return [x, y, distance, color, alpha];
        });
    }
}
export class Eraser extends PenLike {
    name = "橡皮擦";
    constructor() {
        super();
    }
    blend: 0 | 1 = 0;
    GetDistanceArray() {
        const r = this.size - 1;
        return r === 0 ? ([[0, 0, 0]] as PositionArray[]) : drawCircle(r, r);
    }
    StyleConvert(positionArray: PositionArray[]): StyleArray[] {
        return positionArray.map((i) => [...i, 0, 0]);
    }
}

export class PenRect extends PenLike {
    constructor() {
        super();
    }
    GetDistanceArray() {
        return drawRect(this.size);
    }
    StyleConvert(
        positionArray: PositionArray[],
        color: number,
        alpha: number
    ): StyleArray[] {
        return positionArray.map(([x, y, distance]) => {
            return [x, y, distance, color, alpha];
        });
    }
}
